package expansion.doubleArray;

import java.util.Arrays;
public class QuickSort {
    public static void main(String[] args) {
        int[] array = {4,5,8,1,6,2,3,9,7};
        System.out.println(Arrays.toString(array));
        quickSort(array);
        System.out.println(Arrays.toString(array));
    }
    public static void quickSort(int[] array){

        quickSort(array,0,array.length-1);
    }
    public static void quickSort(int[] array,int left,int right){
        if(left>=right){
            return ;
        }
        int base = array[left];
        int i = left;
        int j = right;
        while(i<j){
            while(i<j&&array[j]>=base){
                j--;
            }
            array[i] = array[j];

            while (i<j&&array[i]<=base){
                i++;
            }
            array[j] = array[i];
        }
        array[i] = base;
        quickSort(array,left,i-1);
        quickSort(array,i+1,right);
        /*
        if(left>right){
            System.out.println(Arrays.toString(array));

        }
        int tmp = array[left];
        int j = right,i = left;
        for(;j==i;i++,j--){
            if(array[j]<tmp){
                array[i] = array[j];
            }else{
                continue;
            }
            if(array[i]>tmp){
                array[j] = array[i];
            }else {
                continue;
            }
            array[i] = tmp;
        }
        quickSort(array,left,right);
        */
    }
}
